﻿/* eslint-disable no-useless-escape */
/* eslint-disable eol-last */
/* eslint-disable no-undef */
/* eslint-disable space-before-function-paren */
// const _host = 'http://test.2id.cn'
const _host = ''

var ZLM = {
    API: {
        Data: _host + '/api/layoutdata.ashx', // 数据处理的接口
        Image: _host + '/api/layoutimage.ashx', // 图片处理的接口
        Preview: 'http://test.2id.cn/res/', // 图片预览的url前缀，预览的方法是ZLM.Config.Image加上排版保存的json中图片文件名
        Config: _host + '/api/layoutconfig.ashx', // 从后台加载固定的一些信息，例如背景音乐，加载可供用户选择的背景音乐列表
        App: _host + '/api/app.ashx' // 手机端交互api接口
    },
    Data: {
        Code: '',
        AppId: '',
        OpenId: '',
        IsPlay: true
    },
    WloseWindows: function() { // 关闭手机端页面
        window.opener = null
        window.open('', '_self')
        window.close()
        WeixinJSBridge.call('closeWindow')
    },
    GetParam: function(name) { // 抓取url带有的参数，用法 var code=getParam("code");
        var search = document.location.search
        var pattern = new RegExp('[?&]' + name + '\=([^&]+)', 'g')
        var matcher = pattern.exec(search)
        var items = null
        if (matcher != null) {
            try {
                items = decodeURIComponent(decodeURIComponent(matcher[1]))
            } catch (e) {
                try {
                    items = decodeURIComponent(matcher[1])
                } catch (e) {
                    items = matcher[1]
                }
            }
        }
        return items
    },
    PlayVoice: function(tts) {
        var music = document.getElementById('audio')
        var getcode = ZLM.Data.Code.replace(/(.{1})/g, '$1,')
        info = info.replace(ZLM.Data.Code, getcode)
        var zhText = encodeURI(tts)
        var voicebbUrl = 'https://ss0.baidu.com/6KAZsjip0QIZ8tyhnq/text2audio?tex=' + zhText + '&cuid=dict&lan=zh&ctp=1&pdt=30&vol=100&spd=5'
        music.src = voicebbUrl
        music.play()
        document.addEventListener('touchstart', function() {
            if (ZLM.Data.IsPlay) {
                music.play()
                ZLM.Data.IsPlay = false
            }
        }, false)
        document.addEventListener('WeixinJSBridgeReady', function() {
            if (ZLM.Data.IsPlay) {
                music.play()
                ZLM.Data.IsPlay = false
            }
        }, false)
    },
    mycard: function() {
        window.location.href = 'http://10001.zb.2id.cn/manage/weixin/url.aspx?appid=10001&action=usercenter'
    },
    wxship: function() {
        window.location.href = 'http://10001.hd.2id.cn/wap/wms/login.html?appid=10001'
    },
    authorization: function() {
        window.location.href = 'http://10001.hd.2id.cn/wap/10001/wl/shouquan.html?appid=10001'
    },
    // 获取url参数
    getSearchParams(param) {
        var url = document.location.toString()
        var arrObj = url.split('?')

        if (arrObj.length > 1) {
            var arrPara = arrObj[1].split('&')
            var arr

            for (var i = 0; i < arrPara.length; i++) {
                arr = arrPara[i].split('=')

                if (arr != null && arr[0] === param) {
                    return arr[1]
                }
            }
            return ''
        }
        return ''
    }

}

export default ZLM